﻿// main js file for the gadget
function init()
{
    set_defaults();
    create_tabs();
}

function set_defaults()
{
    tabs = new gadgets.TabSet(module_id, "Profile");
    
    tab_profile_loaded = false;
    tab_networking_loaded = false;
    tab_contacts_loaded = false;
    tab_groups_loaded = false;
    tab_gadgets_loaded = false;
}

function create_tabs()
{
    authenticate();
    
    tabs.addTab("Profile", {
        contentContainer: document.getElementById("profile_tab"),
        callback: populateProfile
    });
    tabs.addTab("Networking", {
        contentContainer: document.getElementById("networking_tab"),
        callback: populateActivities
    });
    tabs.addTab("Contacts", {
        contentContainer: document.getElementById("contacts_tab"),
        callback: populateContacts
    });
    tabs.addTab("Groups", {
        contentContainer: document.getElementById("groups_tab"),
        callback: populateGroups
    });
    tabs.addTab("Gadgets", {
        contentContainer: document.getElementById("gadgets_tab"),
        callback: populateGadgets
    });
}



gadgets.util.registerOnLoadHandler(init);

function authenticate()
{
    if (!useOAuth)
        return;

    osapi.http.get({
        'href': get_rest_people_requestor_self(),
        'format': 'json',
        'oauth_service_name': oauth_service_name,
        'authz': authz_type
    }).execute(log_in);
}

function log_in(data)
{
    show_errors_if_any(data);
    current_owner_id = data.entity.id;
}